$(document).ready(function(){
							
				window.calendarPopup = {
					init:function(opt){
						if(opt) {
							if($.isFunction(opt.editCallback)) this.editCallback = opt.editCallback;
						}
						this.enabled = true;
						this.visible = false;
						$('.eventInfo .event, .eventInfo').click( this.eventInfo = function(e){
							e.stopPropagation();
							calendarPopup.hide();
							offset = $("body").offset();
							left = e.clientX - (offset.left - 15);
							$('.calendarPopup').css({"top":e.pageY-20, "left":left});
							calendarPopup.src = $(e.target);
							calendarPopup.title = calendarPopup.src.text()
							calendarPopup.currentEvent = calendarPopup.src.attr("eventid");
							
							if(calendarPopup.src.hasClass("event")){ calendarPopup.type="event"; }					
							if(calendarPopup.src.hasClass("task")){ calendarPopup.type="task"; }
							calendarPopup.show(calendarPopup.type);
							
						});
						
						if($.isFunction(calendarPopup.editCallback)){
							$('.calendarPopup .content span.edit, .calendarPopup .content p.title').click(	
									this.editEvent = function(){ 
										if (calendarPopup.type == "event") calendarPopup.editCallback(calendarPopup.event); 
									}
							);
						}
						
						
					},
					show:function(type){
						this.visible = true;
						if (!this.enabled){return;}
						this.bound = true;
						if($.browser.msie) {
							$('.calendarPopup').show();
						} else {
							$('.calendarPopup').fadeIn(200);
						}
						
						setTimeout('calendarPopup.bindHide()',100);
						switch(type){
							case "event":
								this.loadEvent(this.currentEvent);
							break;

							case "task":
								this.loadTask();
							break;
						}
						
						
						
					},
					loadContent:function(){
						edit = "";
						if($.isFunction(calendarPopup.editCallback)){ $(".calendarPopup .content span.edit").show(); }
						$('.calendarPopup span.border').css("width","0%");
						
						if (calendarPopup.event.hasOwnProperty("summary")) {
							$('.calendarPopup .content p.title').html(calendarPopup.event.summary).show();
						}
						
						if (calendarPopup.event.hasOwnProperty("start") && calendarPopup.event.hasOwnProperty("end")) { 
							$('.calendarPopup .content .start .date').text(calendarPopup.event.start.date);
							$('.calendarPopup .content .start .time').text(calendarPopup.event.start.time);
							$('.calendarPopup .content .end .date').text(calendarPopup.event.end.date);
							$('.calendarPopup .content .end .time').text(calendarPopup.event.end.time);
							$('.calendarPopup .content p.when').append(edit);
							$('.calendarPopup .content .when').show();
						}
						if(calendarPopup.event.hasOwnProperty("description")) {
							$('.calendarPopup .content .desc .desc').html(calendarPopup.event.description.replace(/\n/g,"<br/>"));
							$('.calendarPopup .content .desc').show();
						}
						if(calendarPopup.event.hasOwnProperty("location")) {
							$('.calendarPopup .content dfn.where').text(calendarPopup.event.location);
							$('.calendarPopup .content p.where').show();
						}
						
						if (calendarPopup.event.hasOwnProperty("attendees_string") && calendarPopup.event.attendees_string !=="") {
							$('.calendarPopup .content dfn.attendees').text(calendarPopup.event.attendees_string);
							$('.calendarPopup .content p.attendees').show();
						}
							
						$('.calendarPopup .content').slideDown(500);
						$('.calendarPopup span.border').animate({width:"100%"},500);
						
					
					},
					bindHide:function(){
						$(document).click(window.calendarPopup.hide);
						calendarPopup.bound = true;
					},
					hide:function(){
						calendarPopup.visible = false;
						$('.calendarPopup').hide();
						$('.calendarPopup .content').hide();
						$('.calendarPopup p').hide();
						$('.calendarPopup .loading').slideDown();
						$('.calendarPopup .content dfn').text("");
						$(".calendarPopup .content span.edit").hide();
						if(calendarPopup.bound){ $(document).unbind('click',window.calendarPopup.hide); calendarPopup.bound = false; }
					},
					loadEvent:function(eventId) {
						$.getJSON('?wicket:bookmarkablePage=:hub.app.wicket.calendar.GetEventInfoServicePage&id=' + eventId ,
							function(data){
								calendarPopup.event = null;
								calendarPopup.event = data;
								$('.calendarPopup .loading').hide(100,calendarPopup.loadContent);
							}
						);
					},

					loadTask:function(){
						
						calendarPopup.event = { "summary": calendarPopup.title };
						$('.calendarPopup .loading').slideUp(100,calendarPopup.loadContent);
					},
					
					disable:function(){
						calendarPopup.enabled = false;
					},
					enable:function(){
						calendarPopup.enabled = true;
					},
					
					refresh:function(){
						$('.eventInfo .event, .eventInfo .task').unbind('click',this.eventInfo);
						$('.calendarPopup .content span.edit, .calendarPopup .content p.title').unbind('click',this.editEvent);
						this.init();
						
						
					},
					
					stop:function(){
						$('.eventInfo .event, .eventInfo .task').unbind('click',this.eventInfo);
						$('.calendarPopup .content span.edit, .calendarPopup .content p.title').unbind('click',this.editEvent);
					}
					
					

					

					
				}
				
				
});